package com.knowledge.plus.比较器.外部比较器.示例;

import java.util.Comparator;

/**
 * 外部比较器
 *
 * @author PF.Tian
 * @since 2022/3/1
 */
public class RecordTimeDescComparator implements Comparator<Record> {
    /**
     * 先对【状态】排序，然后再对【时长】按逆序（倒序）排序
     *
     * @param o1
     * @param o2
     * @return
     */
    @Override
    public int compare(Record o1, Record o2) {
        final int stateCompare = o1.getState().compareTo(o2.getState());
        if (stateCompare == 0) {
            return o2.getTime().compareTo(o1.getTime());
        }
        return stateCompare;
    }
}

